home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / debug.prog / debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-21  |  1.6 KB  |  60 lines

  1. /* 
  2.  * debug.c --
  3.  *
  4.  *    Command to start a process but have it immediately enter
  5.  *    the debugger, before executing any instructions.
  6.  *
  7.  * Copyright 1988 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/cmds/debug.prog/RCS/debug.c,v 1.1 88/10/28 09:04:26 ouster Exp Locker: mendel $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <sig.h>
  25. /*
  26.  * Secret trap door into exec to make it put the process into debug state.
  27.  */
  28.  
  29. extern int _execDebug;
  30.  
  31. main(argc, argv)
  32.     int  argc;
  33.     char *argv[];
  34. {
  35.     int    pid;
  36.     Sig_Action    newAction;
  37.     if (argc < 2) {
  38.     fprintf(stderr, "Usage: %s command arg arg ...\n", argv[0]);
  39.     exit(1);
  40.     }
  41.     pid = getpid();
  42.     printf("Process %X: \"%s\"\n", pid, argv[1]);
  43.  
  44.     /*
  45.      * Besure that SIG_DEBUG is set at the DEFAULT_ACTION.
  46.      */
  47.     newAction.action = SIG_DEFAULT_ACTION;
  48.     newAction.sigHoldMask = 0;
  49.     Sig_SetAction(SIG_DEBUG, &newAction, (Sig_Action *) NULL);
  50.     _execDebug = 1;
  51.     execvp(argv[1], &(argv[1]));
  52.  
  53.     /*
  54.      * The exec failed.
  55.      */
  56.  
  57.     fprintf(stderr, "Couldn't execute \"%s\": %s\n", argv[1], strerror(errno));
  58.     exit(1);
  59. }
  60.